<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Wallpage_model extends CI_Model
{
	
	public function __construct()
	{
		parent::__construct();

	}
	public function get_user_details($id)
	{
		$this->db->select('users.*,users_groups.*');
		$this->db->from('users');
		$this->db->where('users.id = '.$id);
		$this->db->join('users_groups','users.id = users_groups.user_id');
		return $this->db->get()->row_array();
	}
	function userdetails($id)
	{
		$this->db->select('users.*');
    	$this->db->from('users');
    	$this->db->where('users.id =',$id);
		$userdetails = $this->db->get();
		return $userdetails->result();
	}
	function designationbyid($id)
	{
		$this->db->select('users_groups.*,user_type.*');
    	$this->db->from('user_type');
    	$this->db->join('users_groups', 'user_type_id = user_type.id');
		$this->db->where('users_groups.user_id =',$id);
		$designationbyid = $this->db->get();
		return $designationbyid->result();
	}
	function coffeebyid($id)
	{
		$this->db->select('coffee.*');
    	$this->db->from('users');
    	$this->db->join('coffee', 'user_id = users.id');
		$this->db->where('coffee.user_id =',$id);
		$coffeebyid = $this->db->get();
		return $coffeebyid->result();
	}
	function badges_by_id($id)
	{
		$this->db->select('user_badges.*,badges.*');
    	$this->db->from('badges');
    	$this->db->join('user_badges', 'badges_id = badges.id');
		$this->db->where('user_badges.user_id =',$id);
		$badgesid = $this->db->get();
		return $badgesid->result();
	}
	function badges_by_id_array($id)
	{
		$this->db->select('user_badges.*,badges.*');
    	$this->db->from('badges');
    	$this->db->join('user_badges', 'badges_id = badges.id');
		$this->db->where('user_badges.user_id =',$id);
		$badgesid = $this->db->get();
		return $badgesid->result_array();
	}
	function post_insert($insert)
	{
		$this->db->insert('wall_post',$insert);
	}
	function userpost($id)
	{
		$this->db->select('wall_post.*,users.*,wall_post.id AS wallpostid,users.id AS userid');
    	$this->db->from('users');
    	$this->db->join('wall_post', 'from_user_id = users.id');
		$this->db->where('wall_post.to_user_id =',$id);
		$this->db->order_by('wall_post.id', 'desc');
		$userpost = $this->db->get();
		return $userpost->result();
	}
	
	public function delete_wallpost($id)
	{
		return $this->db->delete('wall_post',array('id'=>$id));
	}
	
	function follow_insert($insert)
	{
		$this->db->insert('follow',$insert);
	}
	function followers($id)
	{
		$this->db->select('users.*,follow.*');
    	$this->db->from('follow');
    	$this->db->join('users', 'follower_id = users.id');
		$this->db->where('follow.user_id =',$id);
		$followers = $this->db->get();
		return $followers->result();
	}
	
	function followersarray($id)
	{
		$this->db->select('users.*,follow.*');
    	$this->db->from('follow');
    	$this->db->join('users', 'follower_id = users.id');
		$this->db->where('follow.user_id =',$id);
		$followersarray = $this->db->get();
		return $followersarray->result_array();
	}
	
	function thank_insert($insert)
	{
		$this->db->insert('thanks',$insert);
	}
	function thanksreceived($id)
	{
		$this->db->select('users.*,thanks.*');
    	$this->db->from('thanks');
    	$this->db->join('users', 'from_user_id = users.id');
		$this->db->where('thanks.to_user_id =',$id);
		$thanksreceived = $this->db->get();
		return $thanksreceived->result();
	}
	function starsreceived($id)
	{
		$this->db->select('users.*,stars.*');
    	$this->db->from('stars');
    	$this->db->join('users', 'user_id = users.id');
		$this->db->where('stars.user_id =',$id);
		$starsreceived = $this->db->get();
		return $starsreceived->result();
	}
	function number_of_thanks($id)
	{
		$this->db->select('thanks.from_user_id');
    	$this->db->from('thanks');
    	$this->db->join('users', 'from_user_id = users.id');
		$this->db->where('thanks.to_user_id =',$id);
		$number_of_thanks = $this->db->get();
		return $number_of_thanks->result();
	}
	function number_of_stars($id)
	{
		$this->db->select(',stars.star');
    	$this->db->from('stars');
    	$this->db->join('users', 'user_id = users.id');
		$this->db->where('stars.user_id =',$id);
		$number_of_stars = $this->db->get();
		return $number_of_stars->result_array();
	}


}


	
	
